import {Component, OnInit} from '@angular/core';
/*import { Http } from '@angular/http';*/
import {HttpClient, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
import 'rxjs/add/operator/switchMap';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';

/*import { Http, Response, Headers, RequestOptions,URLSearchParams } from '@angular/http';*/
@Component({
  templateUrl: './getpic2.component.html',
  styleUrls: ['./getpic2.component.css']
})
export class Getpic2Component implements OnInit {

  getpic = {"DH": "170807024", "XH": "2", "AttachXH": "1"};
  myurl = 'http://localhost:3000/posts/pic';
  //myurl = 'http://www.lunan:88/client/app/data/api/300'
  picPathArray: Array<string>;

  constructor(private route: ActivatedRoute,
              private router: Router,
              private http: HttpClient) {

  }


  ngOnInit() {

    this.route.params
      .subscribe((params: ParamMap) => {
        this.getpic.DH = params['DH'];
        this.getpic.XH = params['XH'];
        this.getpic.AttachXH = params['AttachXH'];
        this.getPic();
      })
  }


  getPic() {
    //let returndata = [{"error":"","data":[{"FilePath":"http://localhost:3000/wechat.jpeg"}],"UserName":"ywy"}];
    let tempUrl = this.myurl
      + '/?'
      + "DH=" + this.getpic.DH
      + "&"
      + "XH=" + this.getpic.XH
      + "&"
      + "AttachXH=" + this.getpic.AttachXH;
    console.log(tempUrl);
    /*console.log(returndata[0].data[0].FilePath);*/
    this.http.get(tempUrl).subscribe(returndata => {
      // Read the result field from the JSON response.
      console.log(returndata);
      this.picPathArray = returndata['data'];
      console.log(this.picPathArray);
    });
  }

  goToSignature() {
    this.router.navigate(['/signature', {DH: this.getpic.DH, XH: this.getpic.XH, AttachXH: this.getpic.AttachXH}]);
  }

}
